package cs2114.antiFingerMines;

import student.TestCase;

// -------------------------------------------------------------------------
/**
 * This class tests the MineField class
 *
 * @author Blake Whaley
 * @author Graham McLaughlin (gjm1324)
 * @author William Vuong (wnvuong)
 * @version 2012.29.4
 */
public class MineFieldTest
    extends TestCase
{

    // Variables needed for testing
    private MineField field;
    private Mine      mine;
    private MineField field2;

    /**
     * Sets up the minefield for testing
     */
    public void setUp()
    {
        field = new MineField(720, 480, 10);
    }

    /**
     * tests that placemines works as expected
     */
    public void testPlaceMines()
    {
        int j = 0;
        while (j < 100000)
        {
            field = new MineField(720, 480, 10);
            field.placeMines();
            for (int i = 0; i < field.getField().length; i++)
            {
                assertTrue(field.getField()[i].distanceFrom(field
                .getFingerLocation()) >= 20);
            }
            j++;
        }
    }


    /**
     * Tests getWidth and getHeight
     */
    public void testGetHeightWidth()
    {
        assertEquals(480, (int)field.getHeight());
        assertEquals(720, (int)field.getWidth());
    }


    /**
     * Tests setWidth and setHeight
     *
     * @return
     */
    public void testSetHeightWidth()
    {
        field.setHeight(390);
        field.setWidth(245);
        assertEquals(390, (int)field.getHeight());
        assertEquals(245, (int)field.getWidth());
    }


    /**
     * Tests the set random mines method
     */
    public void testSetRandomMines()
    {
        field = new MineField(480, 480, 10);
        field.setRandomMines();
    }


    /**
     * Tests getEndOfField()
     */
    public void testEndOfField()
    {
        assertEquals(384, (int)field.getEndOfField());
    }


    /**
     * Tets hasWon
     */
    public void testHasWon()
    {
        field.setFingerLocation(20, 385);
        assertTrue(field.hasWon());

        field.setFingerLocation(20, 200);
        assertFalse(field.hasWon());
    }


    /**
     * Tests get size
     */
    public void testSize()
    {
        assertEquals(10, field.size());
    }


    /**
     * Tests isGameOver and getMine
     */
    public void testIsGameOverandGetMine()
    {
        field.setFingerLocation(field.getMine(1).getX(), field.getMine(1)
            .getY());
        assertTrue(field.isGameOver());
    }


    /**
     * Tests the newgame2
     */
    public void testNewGame1()
    {
        field.newGame1(480, 480, 10);
    }
}
